<template>
  <!-- <ContentWrap> -->
    <!-- 搜索工作栏 -->
    <!-- <el-form ref="queryFormRef" :inline="true" :model="queryParams" class="-mb-15px" label-width="68px">
      <el-form-item>
        <el-button plain type="primary" @click="updateForm('create')" v-hasPermi="['system:project:store:create']">
          <Icon class="mr-5px" icon="ep:plus" />
          新增
        </el-button>
      </el-form-item>
    </el-form> -->
  <!-- </ContentWrap> -->

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true">
      <el-table-column align="center" label="仓库名称" prop="storeName" />
      <el-table-column align="center" label="用户组名" prop="groupName" />
      <el-table-column align="center" label="描述" prop="desc"/>
      <el-table-column align="center" label="git地址" prop="store_url" />
      <el-table-column align="center" label="创建时间" prop="createTimeStr" />
      <!-- <el-table-column :width="300" align="center" label="管理">
        <template #default="scope">
          <el-button link type="primary" @click="updateForm('update', scope.row)" v-hasPermi="['system:project:store:update']">
            编辑
          </el-button>
          <el-button link type="danger" @click="handleDelete(scope.row.id)" v-hasPermi="['system:project:store:delete']">
            删除
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页 -->
    <Pagination v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNo" :total="total"
      @pagination="getList" />

    <!-- 表单弹窗：添加/修改 -->
    <StoreForm ref="formRef" @success="getList" />
  </ContentWrap>

</template>
<script lang="ts" setup>
import * as ProjectApi from '@/api/project'
import StoreForm from './StoreForm.vue'
defineOptions({ name: 'Store' })
const { currentRoute } = useRouter() // 路由对象
const { query } = unref(currentRoute)
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([] as any) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  projectId: query.projectId
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ProjectApi.getProjectStoreList(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}


/** 添加修改操作 */
const formRef = ref()

const updateForm = (type: string, row?: object) => {
  formRef.value.open(type, row)
}

// 删除
const handleDelete = async (id) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await ProjectApi.deleteProjectStore({ id ,projectId:query.projectId})
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch { }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
<style scoped lang="scss">

</style>
